package com.jzo2o.customer.controller.consumer;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 普通用户地址簿相关接口
 * @author 45505
 */
@RestController("ConsumerAddressBookController")
@RequestMapping("/consumer/address-book")
@Api(tags = "用户端 - 普通用户地址簿相关接口")
public class AddressBookController {

    @Resource
    private IAddressBookService addressBookService;

    @PostMapping
    @ApiOperation("地址薄新增服务")
    public void addressBook(@RequestBody AddressBookUpsertReqDTO addressBookUpsertReqDTO) {
        addressBookService.addressBook(addressBookUpsertReqDTO);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询地址薄服务")
    public PageResult<AddressBook> pageQuery(AddressBookPageQueryReqDTO addressBookPageQueryReqDTO){
        return addressBookService.pageQueryO(addressBookPageQueryReqDTO);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询地址簿回显")
    public AddressBook echoById(@PathVariable("id") Long id) {
        return addressBookService.echoById(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("地址簿信息修改")
    public void updateAddressBookById(@RequestBody AddressBookUpsertReqDTO addressBookUpsertReqDTO,@PathVariable("id")Long id) {
        addressBookService.updateAddressBookById(addressBookUpsertReqDTO,id);
    }

    @DeleteMapping("/batch")
    @ApiOperation("地址簿信息批量删除")
    public void batchDeleteByIds(@RequestBody List<Long> ids) {
        addressBookService.batchDeleteByIds(ids);
    }

    @PutMapping("/default")
    @ApiOperation("地址簿设置/取消默认地址")
    public void updateDefault(@RequestParam("flag")Integer flag,@RequestParam("id")Long id) {
        addressBookService.updateDefault(flag, id);
    }

    @GetMapping("/defaultAddress")
    @ApiOperation("地址簿获取默认地址")
    public AddressBook defaultAddress() {
        return addressBookService.defaultAddress();
    }



}
